home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 701-725 / 708 / intuisup / intuisup42.lha / Intuisup / source.lha / Editor / fonts.c < prev    next >
C/C++ Source or Header  |  1992-01-07  |  4KB  |  161 lines

  1. /* $Revision Header *** Header built automatically - do not edit! ***********
  2.  *
  3.  *    (C) Copyright 1991 by Torsten Jürgeleit
  4.  *
  5.  *    Name .....: fonts.c
  6.  *    Created ..: Tuesday 31-Dec-91 14:29:10
  7.  *    Revision .: 1
  8.  *
  9.  *    Date        Author                 Comment
  10.  *    =========   ====================   ====================
  11.  *    07-Jan-92   Torsten Jürgeleit      update to new ISUP font routines
  12.  *    31-Dec-91   Torsten Jürgeleit      Created this file!
  13.  *
  14.  ****************************************************************************
  15.  *
  16.  *    Font support routines
  17.  *
  18.  * $Revision Header ********************************************************/
  19.  
  20.     /* Includes */
  21.  
  22. #include "includes.h"
  23. #include "defines.h"
  24. #include "imports.h"
  25. #include "protos.h"
  26.  
  27.     /* Open template font with given attributes */
  28.  
  29.    struct TextAttr *
  30. open_template_font_by_attributes(struct TemplateList  *tl, BYTE *name,
  31.                                    USHORT ysize)
  32. {
  33.    struct TextAttr  search_ta, *avail_ta, *ta = NULL;
  34.  
  35.    /* Try to open given font */
  36.    search_ta.ta_Name  = (STRPTR)name;
  37.    search_ta.ta_YSize = ysize;
  38.    search_ta.ta_Style = FS_NORMAL;
  39.    search_ta.ta_Flags = FPF_ROMFONT;
  40.    if (avail_ta = IAskFont(pri, &search_ta)) {
  41.       struct TemplateFont  *tf;
  42.  
  43.       /* Search given template font in font list */
  44.       ysize = avail_ta->ta_YSize;
  45.       for (tf = get_head((struct List *)&tl->tl_Fonts); tf;
  46.                 tf = get_succ((struct Node *)&tf->tf_MinNode)) {
  47.       if (!Strcmp(name, (BYTE *)tf->tf_TextAttr.ta_Name) &&
  48.                     ysize == tf->tf_TextAttr.ta_YSize) {
  49.          tf->tf_UseCount++;
  50.          ta = &tf->tf_TextAttr;
  51.          break;
  52.       }
  53.       }
  54.       if (!ta) {
  55.  
  56.      /* Create new template font */
  57.      if (tf = AllocMem((LONG)sizeof(struct TemplateFont),
  58.                                (LONG)MEMF_PUBLIC)) {
  59.         if (duplicate_string(name, (BYTE **)&tf->tf_TextAttr.ta_Name) !=
  60.                              EDITOR_STATUS_NORMAL) {
  61.            FreeMem(tf, (LONG)sizeof(struct TemplateFont));
  62.         } else {
  63.  
  64.            /* Init template font and add it to font list */
  65.            ta = &tf->tf_TextAttr;
  66.            ta->ta_YSize    = avail_ta->ta_YSize;
  67.            ta->ta_Style    = avail_ta->ta_Style;
  68.            ta->ta_Flags    = avail_ta->ta_Flags;
  69.            tf->tf_UseCount = 1;
  70.            AddTail((struct List *)&tl->tl_Fonts,
  71.                         (struct Node *)&tf->tf_MinNode);
  72.         }
  73.      }
  74.       }
  75.    }
  76.    return(ta);
  77. }
  78.     /* Open template font with given number */
  79.  
  80.    struct TextAttr *
  81. open_template_font_by_num(struct TemplateList  *tl, USHORT num)
  82. {
  83.    struct TemplateFont  *tf;
  84.    struct TextAttr      *ta;
  85.  
  86.    /* Search given template font in font list */
  87.    if (!(tf = get_node((struct List *)&tl->tl_Fonts, num))) {
  88.       ta = NULL;
  89.    } else {
  90.       tf->tf_UseCount++;
  91.       ta = &tf->tf_TextAttr;
  92.    }
  93.    return(ta);
  94. }
  95.     /* Get number of template font from font list */
  96.  
  97.    USHORT
  98. get_template_font_num(struct TemplateList  *tl, struct TextAttr  *ta)
  99. {
  100.    struct TemplateFont  *tf;
  101.    USHORT num = 0;
  102.  
  103.    /* Search given template font in font list */
  104.    for (tf = get_head((struct List *)&tl->tl_Fonts); tf;
  105.                 tf = get_succ((struct Node *)&tf->tf_MinNode)) {
  106.       if (ta == &tf->tf_TextAttr) {
  107.      break;
  108.       } else {
  109.      num++;
  110.       }
  111.    }
  112.    return(num);
  113. }
  114.     /* Close template font with given attributes */
  115.  
  116.    VOID
  117. close_template_font(struct TemplateList  *tl, struct TextAttr  *ta)
  118. {
  119.    if (ta) {
  120.       struct TemplateFont  *tf;
  121.  
  122.       /* Search given template font in font list */
  123.       for (tf = get_head((struct List *)&tl->tl_Fonts); tf;
  124.                 tf = get_succ((struct Node *)&tf->tf_MinNode)) {
  125.      if (ta == &tf->tf_TextAttr) {
  126.  
  127.         /* Close font and check if its in use yet */
  128.         if (!--tf->tf_UseCount) {
  129.  
  130.            /* Remove and free template font from font list */
  131.            Remove((struct Node *)&tf->tf_MinNode);
  132.            free_template_font(tf);
  133.         }
  134.         break;
  135.      }
  136.       }
  137.    }
  138. }
  139.     /* Free template font list */
  140.  
  141.    VOID
  142. free_font_list(struct TemplateList  *tl)
  143. {
  144.    struct TemplateFont  *tf;
  145.    struct List          *list = (struct List *)&tl->tl_Fonts;
  146.  
  147.    while (tf = (struct TemplateFont *)RemHead(list)) {
  148.       free_template_font(tf);
  149.    }
  150. }
  151.     /* Free template font */
  152.  
  153.    VOID
  154. free_template_font(struct TemplateFont  *tf)
  155. {
  156.    if (tf) {
  157.       DosFreeMem(tf->tf_TextAttr.ta_Name);
  158.       FreeMem(tf, (LONG)sizeof(struct TemplateFont));
  159.    }
  160. }
  161.